export const MaintenanceMan = {
  isEmpty(str) {
    if (str === null || ''.equals(str)) {
      return true
    } else { return false }
  },
  isRegisterCode(s) {
    const flag = /^\d{20}$/.test(s)
    return flag
  },
  isSafeCode(s) {
    const flag = /^\d{6}$/.test(s)
    if (flag === false) {
      console.log(s)
      // System.out.println(s)
    }
    return flag
  },
  ArrayCheck(str) {
    return true
  },
  RegexCheck(re, str) {
    // Pattern p = Pattern.compile(re)
    const m = p.matcher(str)
    const d = m.matches()
    return d
  },
  isMobile(s) {
    const flag = /^1[38]\\d{9}$/.test(s) // 判断功能 定义手机好规则
    return flag
  },
  isIDCard( IDNumber) {
    if(this.isEmpty(IDNumber))
      return false;
    
      let regularExpression = "(^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|" +
              "(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)";

      let matches = regularExpression.test(IDNumber)

      //判断第18位校验值
      if (matches){
          if (IDNumber.length() == 18) {
              try {
                  let charArray = IDNumber.toCharArray();
                  //前十七位加权因子
                  let idCardWi = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 }
                  //这是除以11后，可能产生的11位余数对应的验证码
                  let idCardY = '1, 0, X, 9, 8, 7, 6, 5, 4, 3, 2'
                  let sum = 0;
                  for (var i = 0; i < idCardWi.length; i++) {
                      let current = Integer.parseInt(String.valueOf(charArray[i]));
                      let count = current * idCardWi[i];
                      sum += count;
                  }
                  let idCardLast = charArray[17];
                  let idCardMod = sum % 11;
                  if (idCardY[idCardMod].toUpperCase().equals(String.valueOf(idCardLast).toUpperCase())) {
                      return true;
                  } else {
                      return false;
                  }

              } catch ( e) {
                  e.printStackTrace();
                  return false;
              }
          }

      }
      return matches;
  },
  isDateTime( str) {
    if(this.isEmpty(str))
      return false;
  else{
    let re = "\\d{4}(\\-|\\/|.)\\d{1,2}\\1\\d{1,2}";
      return RegexCheck(re,str);
    }
  },
  isHKIdCard( str) {       
    if(this.isEmpty(str))
      return false;
  else{   
      let re = "^[HMhm]{1}([0-9]{10}|[0-9]{8})$";
      return RegexCheck(re,str);
    }
  },
  isForeignIdCard(str) {
    if(this.isEmpty(str))
      return false;
  else {
    let re = "^[A-Z]{3}\\d{6}(?:0[1-9]|1[021])(?:0[1-9]|[21]\\d|3[10])\\d{2}$";
    return RegexCheck(re,str);
    }   
  },
  isArmyIdCard(str) {
    if(this.isEmpty(str))
      return false;
  else{
      let re = "^[a-zA-Z0-9]{7,21}$";
      return RegexCheck(re,str);
    }  
  },
  isPassport(str) {
    if(this.isEmpty(str))
      return false;
  else{
      let re = "^[a-zA-Z0-9]{3,21}$";
      return RegexCheck(re,str);
    } 
  }
}

export default MaintenanceMan
